define(function(require){
    var main =require('/static/main.js');
    require('/static/ajaxfileupload.js');
    var m = new main();
    function Cont(){
        this.Fun._init();
    }
    Cont.prototype.Fun = {
        _init:function(){
            this.getlist();
            this.bindEvent();
        },
        bindEvent:function(){
        },
        getlist:function(){
            var _this = this;
            var emdataa = [];
            var param = {};
            var sort = 0;
            var table = $('#datatable').dataTable({
                'ordering':false,
                "serverSide": true,
                "searching":false,
                'bLengthChange': false,
                'bPaginate': true,
                "bDestory": true,
                "bRetrieve": true,
                "bFilter":false,
                "bSort": false,
                "bProcessing": true,
                "autoWidth": false,
                ajax: function (data, callback, settings) {
                    //封装请求参数
                    param.PageSize = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                    param.start = data.start;//开始的记录序号
                    param.PageNo = (data.start / data.length)+1;//当前页码
                    param.ENTCode = _this.ENTCode;//当前页码


                    sort = (param.PageNo-1)*param.PageSize;
                    //ajax请求数据
                    $.ajax({
                        type: "POST",
                        url: "/examine/get-withdraw-list",
                        cache: false,  //禁用缓存
                        data: param,  //传入组装的参数
                        dataType: "json",
                        success: function (result) {
                            console.log(result.data);
                            var returnData = {};
                            returnData.draw = data.draw;
                            returnData.recordsTotal = result.total;
                            returnData.recordsFiltered = result.total;
                            returnData.data = result.data;
                            emdataa = result.data;
                            callback(returnData);
                        }
                    });
                },
                "aoColumns":[
                    {"mDataProp": 'ENDCode'},
                    {"mDataProp": 'WithdrawAmount'},
                    {"mDataProp": 'WithdrawMethod',
                        render:function(data){
                            var WithdrawMethod = '';
                            switch(data){
                                case 100:WithdrawMethod = '微信'; break;
                                case 200:WithdrawMethod = '支付宝'; break;
                                case 300:WithdrawMethod = '银行卡'; break;
                            }
                            return WithdrawMethod;
                        }
                    },
                    {"mDataProp": 'Cardholder'},
                    {"mDataProp": 'OpeningBank'},
                    {"mDataProp": 'BankId'},

                    {"mDataProp": 'CreateTime',
                        render:function(data){
                            return m.formatTimeAll2(data);
                        }
                    },
                    {"mDataProp": 'WithdrawStatusName'},
                    {
                        "mDataProp": "ApplyId",
                        "sClass": "option_btn",
                        "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                            // console.log(arguments);
                            $(nTd).html('<span class="btn_detial AuditBtn" data-id="'+sData+'" data-type="100">通过</span>\
                                            <span class="btn_del AuditBtn"  data-id="'+sData+'" data-type="200">拒绝</span>');

                        }
                    }
                ]
            }).api();

            // 点击搜索
            $('#btnSearch').click(function(){
                param.ENTCode = $('.ENTCode').val();
                var table = $('#datatable').DataTable();
                table.ajax.reload();

            });
            // 点击重置按钮
            $('#btnRefresh').click(function(){
                $('.ENTCode').val('');
                param.ENTCode = '';
                var table = $('#datatable').DataTable();
                table.ajax.reload();
            });

            //编辑
            $(document).on('click','.AuditBtn',function(){
                var type = parseInt($(this).attr("data-type"));
                var ApplyId = $(this).attr("data-id");
                if(type == 100){
                    _this.ProbationAudit(ApplyId,200);
                }else{
                    layer.prompt({title: '请填写拒绝理由', formType: 2}, function(text, index){
                        layer.close(index);
                        _this.ProbationAudit(ApplyId,300,text);
                    });
                }
            });
        },
        ProbationAudit:function(ApplyId,WithdrawStatus,AuditRemark){
            $.ajax({
                type: "POST",
                url: "/examine/withdraw-audit",
                data :{ApplyId:ApplyId,WithdrawStatus:WithdrawStatus,AuditRemark:AuditRemark},
                dataType: "json",
                success: function (ret){
                    isactive = false;
                    if(ret.IsBizSuccess){
                        var table1 = $('#datatable').DataTable();
                        table1.ajax.reload();
                    }else{
                        layer.msg(ret.ErrMsg);
                    }
                }
            });
        }
    }
    var a = new Cont();

})